package com.itheima.config;

import com.itheima.pojo.GoodInfo;
import com.itheima.util.ElasticUtils;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EsClientConfig {
    /**
     * 操作es的客户端对象
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("192.168.200.128",9200)
                )
        );
        return restHighLevelClient;
    }
    /**
     * 操作es的工具类对象
     * @return
     */
    @Bean
    public ElasticUtils esUtils(){
        return new ElasticUtils(restHighLevelClient(),"goods", GoodInfo.class);
    }
}
